package luanvan.app.foodnote.library;

import java.util.HashMap;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class SettingManager {

	// Shared Preferences
	SharedPreferences pref;
	
	// Editor for Shared preferences
	Editor editor;
	
	// Context
	Context _context;
	
	// Shared pref mode
	int PRIVATE_MODE = 0;
	
	// Sharedpref file name
	private static final String PREF_NAME = "FoodNoteSetting";
	
	// User name
	public static final String KEY_SETTING = "setting";
	
	public static boolean KEY_CHECK = true;
	
	@SuppressLint("CommitPrefEdits")
	public SettingManager(Context context){
		this._context = context;
		pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
		editor = pref.edit();
	}
	
	public void createSetting(String setting){
		
		editor.putString(KEY_SETTING, setting);
		editor.commit();
	}
	
	public HashMap<String, String> getSetting(){
		
		HashMap<String, String> setting = new HashMap<String, String>();
		setting.put(KEY_SETTING, pref.getString(KEY_SETTING, "Personal"));
		
		return setting;
	}
	
	public void checkChanged(String setting){
		if(KEY_SETTING.equals(setting))
			KEY_CHECK = false;
	}
	public void clearSetting(){
		editor.clear();
		editor.commit();
	}
}
